package com.nike.amoeba.ui.frg

import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import com.nike.amoeba.R
import com.nike.amoeba.adapter.TaskAssetAdapter
import com.nike.amoeba.ext.init
import com.nike.amoeba.viewmodel.TaskModel
import com.kingja.loadsir.core.LoadService
import com.nike.amoeba.api.UIHelper
import com.nike.amoeba.base.BaseFragment
import com.nike.amoeba.databinding.FOrderBinding
import com.nike.amoeba.ext.ORDER_TYPE
import com.nike.amoeba.ext.bindViewPager2
import com.nike.amoeba.viewmodel.RfidModel

/**
 * @Author nike
 * @Date 2023/7/7 11:59
 * @Description
 */
class OrderFrg : BaseFragment<TaskModel, FOrderBinding>(){

    val adapter: TaskAssetAdapter by lazy { TaskAssetAdapter(arrayListOf()) }

    lateinit var loadsir: LoadService<Any>

    var fragments: ArrayList<Fragment> = arrayListOf()

    val taskModel: TaskModel by activityViewModels()

    val rfidModel: RfidModel by activityViewModels()

    override fun initView(savedInstanceState: Bundle?) {
        mDatabind.viewmodel = mViewModel

        //初始化viewpager2
        var bundle = Bundle()

        val takeAssetFrg = TakeAssetFrg()
        takeAssetFrg.arguments = bundle
        fragments.add(takeAssetFrg)

        val taskStockFrg = TaskStockFrg()
        taskStockFrg.arguments = bundle
        fragments.add(taskStockFrg)

        mDatabind.includeViewpager.viewPager.init(this, fragments)
        var mTitles =
            arrayListOf(
                getString(R.string.asset),
                getString(R.string.stock),
            )

        mDatabind.includeViewpager.magicIndicator.bindViewPager2(mDatabind.includeViewpager.viewPager, mTitles)
        mDatabind.includeViewpager.viewPager.offscreenPageLimit = mTitles.size

        mDatabind.includeSearch.etText.addTextChangedListener(object : TextWatcher{
            override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
            }

            override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
                taskModel.orderSerch.value = p0.toString()
            }

            override fun afterTextChanged(p0: Editable?) {
            }
        })

        mDatabind.includeSearch.ivQr.setOnClickListener {
            UIHelper.startZxingAct(ORDER_TYPE)
        }

    }

}